/**
 * 
 */
package com.furschina.aop;

import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import com.furschina.model.Article;
import com.furschina.model.ArticleRecord;
import com.furschina.service.ArticleRecordService;

/**
 * @author iday
 * 
 */
@Component
@Aspect
public class ArticleRecordAspect {
	private ArticleRecordService articleRecordService;

	/**
	 * @param articleRecordService
	 *            the articleRecordService to set
	 */
	public void setArticleRecordService(
			ArticleRecordService articleRecordService) {
		this.articleRecordService = articleRecordService;
	}

	@Pointcut("target(com.furschina.service.ArticleService)")
	public void articlePointCut() {
	}

	@After("articlePointCut() && execution(* create(..)) && args(article)")
	public void articleCreate(Article article) {
		articleRecordService.create(new ArticleRecord(article));
	}

	@AfterReturning(pointcut = "articlePointCut() && execution(* findForView(..))", returning = "article")
	public void articleView(Article article) {
		articleRecordService.incrViews(article);
	}
}
